class Solution {
public:
    string addBinary(string a, string b) {
        int carry=0;
       // reverse(a.begin(),a.end());
       // reverse(b.begin(),b.end());
        string ret;
        int i=a.size()-1;
        int j=b.size()-1;
        while(i>=0||j>=0||carry)
        {
            if(i>=0)carry+=a[i--]-'0';
            if(j>=0)carry+=b[j--]-'0';
            ret+=carry%2+'0';
            carry/=2;
        }
        reverse(ret.begin(),ret.end());
        return ret;
    }
};
